package com.ybb.production.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ybb.production.domain.GarmentProductionBianfei;
import com.ybb.production.dto.GarmentProductionPrintDTO;
import com.ybb.production.responce.GarmentBianfeiCompleteDetailResp;
import com.ybb.production.responce.GarmentPrintTicketResp;
import com.ybb.production.service.IGarmentProductionBianfeiService;
import com.yubb.common.core.controller.BaseController;
import com.yubb.common.core.domain.AjaxResult;
import com.yubb.common.core.domain.R;
import com.yubb.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 编菲信息Controller
 *
 * @author dengjie
 * @date 2023-09-09
 */
@RestController
@RequestMapping("/production/bianfei")
@Api(tags = "编菲信息")
public class GarmentProductionBianfeiController extends BaseController {
    @Autowired
    private IGarmentProductionBianfeiService garmentProductionBianfeiService;

    /**
     * 查询编菲信息列表
     */
    @RequiresPermissions("production:bianfei:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询编菲信息列表")
    public TableDataInfo<GarmentProductionBianfei> list(GarmentProductionBianfei garmentProductionBianfei) {
        startPage();
        List<GarmentProductionBianfei> list = garmentProductionBianfeiService.selectGarmentProductionBianfeiList(garmentProductionBianfei);
        return getDataTable(list);
    }


    @RequiresPermissions("production:bianfei:add")
    @PostMapping("/editUpNum")
    @ApiOperation(value = "编菲上数")
    public AjaxResult editUpNum(@RequestBody List<GarmentProductionBianfei> bianfeiParam) {
        return toAjax(garmentProductionBianfeiService.editUpNum(bianfeiParam));
    }


    @RequiresPermissions("production:bianfei:edit")
    @PostMapping("/editUpNumCancel/{ids}")
    @ApiOperation(value = "编菲撤数")
    public R editUpNumCancel(@PathVariable String ids) {
        int result = garmentProductionBianfeiService.editUpNumCancel(ids);
        if (result > 0) {
            return R.ok("撤数成功！");
        } else {
            return R.fail("撤数失败，无法撤销不是自己的记录!");
        }
    }

    @RequiresPermissions("production:bianfei:list")
    @PostMapping("/qryRemainingUpNums")
    @ApiOperation(value = "查询剩余上数数量，入参数：cuttindbedId和processId")
    public R qryRemainingUpNums(@RequestBody GarmentProductionBianfei bianfei) {
        return R.ok(garmentProductionBianfeiService.qryUpNums(bianfei));
    }

    @RequiresPermissions("production:bianfei:list")
    @PostMapping("/qryPrintSetting")
    @ApiOperation(value = "打印票菲设置查询")
    public R qryPrintSetting() {
        return R.ok(garmentProductionBianfeiService.qryPrintSetting());
    }


    @RequiresPermissions("production:bianfei:add")
    @PostMapping("/addPrintSetting")
    @ApiOperation(value = "打印票菲设置保存")
    public AjaxResult addPrintSetting(@RequestBody JSONObject printSetting) {
        return toAjax(garmentProductionBianfeiService.addPrintSetting(printSetting));
    }

    @RequiresPermissions("production:bianfei:list")
    @PostMapping("/qryBianfeiByBundleNo/{cuttingBedId}")
    @ApiOperation(value = "打印票菲扎号列表")
    public R<List<GarmentBianfeiCompleteDetailResp>> qryBianfeiByBundleNo(@PathVariable Long cuttingBedId) {
        return R.ok(garmentProductionBianfeiService.qryBianfeiByBundleNo(cuttingBedId));
    }

    @RequiresPermissions("production:bianfei:list")
    @PostMapping("/printTicket")
    @ApiOperation(value = "打印票菲")
    public R<List<GarmentPrintTicketResp>> printTicket(@RequestBody GarmentProductionPrintDTO printDTO) {
        return R.ok(garmentProductionBianfeiService.printTicket(printDTO));
    }
}
